package com.iretailer.report.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iretailer.report.dto.PageResult;
import com.iretailer.report.dto.QueryOption;
import com.iretailer.report.mapper.TagTypeMallsMapper;
import com.iretailer.report.model.MallTagType;
import com.iretailer.report.model.TagTypeMalls;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Auther: xjw
 * @Date: 2019/7/18 0018 14:59
 * @Description:
 */
@Service
public class TagTypeMallsService extends ServiceImpl<TagTypeMallsMapper, TagTypeMalls> {

    @Autowired
    private TagTypeMallsMapper tagTypeMallsMapper;

    public PageResult gridMallTagType(String companyId, String companyName, String mallName, String name, QueryOption queryOption) {
        Page<MallTagType> page = new Page<>(1, Long.MAX_VALUE);
        QueryWrapper<MallTagType> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("1", 1);
        if (companyId != null) {
            queryWrapper.eq("companyId", companyId);
        }
        if (companyName != null) {
            queryWrapper.eq("companyName", companyName);
        }
        if (mallName != null) {
            queryWrapper.like("mallName", mallName);
        }
        if (name != null) {
            queryWrapper.like("name", name);
        }
        queryOption.judge(page, queryWrapper);
        queryWrapper.orderByAsc("companyName").orderByAsc("ranked").orderByAsc("name").orderByAsc("mallName");
        tagTypeMallsMapper.selectPageMallTagType(page, queryWrapper);
        return new PageResult<>(page.getTotal(), page.getRecords());
    }

    public List<MallTagType> selectMallTagTypeByMallIds(List<String> mallIds) {
        return tagTypeMallsMapper.selectMallTagTypeByMallIds(mallIds);
    }

}
